package homework11;

public class Bus {
	private boolean flag=false;
	public synchronized void mainMeth(){
		while (false==flag){
			try{
				wait();
			}catch(InterruptedException e){
				e.printStackTrace();
			}
		}
		for (int i=0;i<5;i++){
			System.out.println(Thread.currentThread().getName()+i);
		}
		flag=false;
		notify();
	}
	public synchronized void subMeth(){
		while(true==flag){
			try{
				wait();
			}catch(InterruptedException e){
				e.printStackTrace();
			}
		}
		for (int i=0;i<3;i++){
			System.out.println(Thread.currentThread().getName()+i);
		}
		flag=true;
		notify();
	}
}
